package com.jari.lg.service.profile.carstatistic;

import com.jari.lg.domain.DevBase;
import com.jari.lg.domain.FakePlateCarEntity;
import com.jari.lg.mapper.FakePlateCarEntityMapper;
import com.jari.lg.utils.BaseData;
import com.jari.lg.utils.Constants;
import com.jari.lg.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FakePlateCarService {

    @Autowired
    private FakePlateCarEntityMapper fakePlateCarEntityMapper;

    /*
    * 套牌车，每天造1000条记录
    * */
    @Scheduled(cron = "* */1 * * * ?")
    public void makeInfo(){
        FakePlateCarEntity entity;
        List<DevBase> checkpointList = BaseData.checkpointList;
        for(DevBase devBase : checkpointList){
            entity =  generate(devBase, checkpointList.get(Utils.makeRandInt(checkpointList.size())));
            fakePlateCarEntityMapper.insert(entity);
        }
    }

    private FakePlateCarEntity generate(DevBase first, DevBase second){
        FakePlateCarEntity  entity = new FakePlateCarEntity();
        entity.setCreator("SYS");
        entity.setDatastatus(Constants.DATA_STATUS_ONE);
        entity.setGmtcreate(new Date());
        entity.setDatetime(new Date());
        entity.setFirstappearcpcode(first.getDevicecode());
        entity.setFirstappearcpname(first.getDevicename());
        entity.setFirstappeardatetime(new Date());
        entity.setSecondappearcpcode(second.getDevicecode());
        entity.setSecondappearcpname(second.getDevicename());
        entity.setSecondappeardatetime(Utils.makeAfterDate(Utils.makeRandInt(60)));
        entity.setPlatenumber(Utils.createPlateNumber());
        entity.setPlatetype(Utils.createPlateType());
        return entity;
    }

}
